<?php

/**
 * Routing debugger template.
 *
 * This file is part of the Nette Framework.
 * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
 *
 * @param PresenterRequest $request
 * @param array    $routers
 */

use Nette\Debug;
use Nette\Application\Presenter;

?>

<style type="text/css">
/* <![CDATA[ */
	#routingDebugger {
		position: fixed;
		_position: absolute;
		right: 5px;
		top: 5px;
		z-index: 23177;
		padding: 5px;
		font: 9pt/1.5 Consolas, monospace !important;
		color: black;
		background: #F5F5F5;
		border: 1px dotted gray;
	}

	#routingDebugger div {
		display: none;
	}

	#routingDebugger * {
		color: inherit;
		background: inherit;
		text-align: inherit;
	}

	#routingDebuggerIcon {
		padding: 4px;
		top: 0;
		right: 0;
		line-height: 1;
		color: black;
		text-decoration: none;
	}

	#routingDebugger h2 {
		font-size: 120%;
		color: black;
	}

	#routingDebugger table {
		padding: 0;
		margin: 0;
		border-collapse: collapse;
	}

	#routingDebugger table td, #routingDebugger table th {
		color: #444;
		background: #FFF;
		border: 1px solid #CCC;
		padding: 3px 6px;
		text-align: left;
	}

	#routingDebugger table th {
		color: #165ca3;
		background: #DDD;
		font-size: 90%;
	}

	#routingDebugger .yes td {
		color: green;
		font-weight: bold;
	}

	#routingDebugger .may td {
		color: #67F;
	}

	#routingDebugger pre, #routingDebugger code {
		font: 9pt/1.5 Consolas, monospace !important;
		display: inline;
		margin: 0;
		padding: 0;
		border: 0;
	}

/* ]]> */
</style>


<div id="routingDebugger">
	<a id="routingDebuggerIcon" href="#"><?php echo empty($request) ? 'no route' : htmlSpecialChars($request->getPresenterName() . ':' . (isset($request->params[Presenter::ACTION_KEY]) ? $request->params[Presenter::ACTION_KEY] : Presenter::$defaultAction)) ?> <abbr>&#x25ba;</abbr></a
	><div>
	<?php if (!empty($request)): ?>
		<?php $params = $request->getParams() ?>
		<h2><?php echo htmlSpecialChars($request->getPresenterName() . ':' . (isset($params[Presenter::ACTION_KEY]) ? $params[Presenter::ACTION_KEY] : Presenter::$defaultAction)) ?></h2>
		<?php if (empty($params)): ?>
			<p>No parameters.</p>

		<?php else: ?>
			<table>
			<thead>
			<tr>
				<th>Parameter</th>
				<th>Value</th>
			</tr>
			</thead>
			<tbody>
			<?php unset($params[Presenter::ACTION_KEY]) ?>
			<?php foreach ($params as $key => $value): ?>
			<tr>
				<td><code><?php echo htmlSpecialChars($key) ?></code></td>
				<td><?php if (is_string($value)):?><code><?php echo htmlSpecialChars($value) ?></code><?php else: echo Debug::dump($value, TRUE); endif ?></td>
			</tr>
			<?php endforeach ?>
			</tbody>
			</table>
		<?php endif ?>
	<?php endif ?>


	<h2>Routers</h2>

	<?php if (empty($routers)): ?>
		<p>No routers defined.</p>

	<?php else: ?>
		<table>
		<thead>
		<tr>
			<th>Matched?</th>
			<th>Class</th>
			<th>Mask</th>
			<th>Defaults</th>
			<th>Request</th>
		</tr>
		</thead>

		<tbody>
		<?php foreach ($routers as $router): ?>
		<tr class="<?php echo $router['matched'] ?>">
			<td><?php echo $router['matched'] ?></td>

			<td><code><?php echo htmlSpecialChars($router['class']) ?></code></td>

			<td><code><strong><?php echo htmlSpecialChars($router['mask']) ?></strong></code></td>

			<td><code>
			<?php foreach ($router['defaults'] as $key => $value): ?>
				<?php echo htmlSpecialChars($key), "&nbsp;=&nbsp;", is_string($value) ? htmlSpecialChars($value) : str_replace("\n</pre", '</pre', Debug::dump($value, TRUE)) ?><br>
			<?php endforeach ?>
			</code></td>

			<td><?php if ($router['request']): ?><code>
			<?php $params = $router['request']->getParams(); ?>
			<strong><?php echo htmlSpecialChars($router['request']->getPresenterName() . ':' . (isset($params[Presenter::ACTION_KEY]) ? $params[Presenter::ACTION_KEY] : Presenter::$defaultAction)) ?></strong><br>
			<?php unset($params[Presenter::ACTION_KEY]) ?>
			<?php foreach ($params as $key => $value): ?>
				<?php echo htmlSpecialChars($key), "&nbsp;=&nbsp;", is_string($value) ? htmlSpecialChars($value) : str_replace("\n</pre", '</pre', Debug::dump($value, TRUE)) ?><br>
			<?php endforeach ?>
			</code><?php endif ?></td>
		</tr>
		<?php endforeach ?>
		</tbody>
		</table>
	<?php endif ?>
	</div>
</div>


<script type="text/javascript">
/* <![CDATA[ */
document.getElementById('routingDebuggerIcon').onclick = function(e) {
	var arrow = this.getElementsByTagName('abbr')[0];
	var panel = this.nextSibling;
	var collapsed = panel.currentStyle ? panel.currentStyle.display == 'none' : getComputedStyle(panel, null).display == 'none';

	arrow.innerHTML = collapsed ? String.fromCharCode(0x25bc) : String.fromCharCode(0x25ba);
	panel.style.display = collapsed ? 'block' : 'none';
	arrow.parentNode.style.position = collapsed ? 'absolute' : 'static';

	document.cookie = 'routingDebuggerVisible=' + collapsed*1 + '; path=/';
	return false;
}

document.body.appendChild(document.getElementById('routingDebugger'));

if (document.cookie.indexOf('routingDebuggerVisible=1') > -1) {
	document.getElementById('routingDebuggerIcon').onclick();
}
/* ]]> */
</script>
